package com.yuanxing.oushangyidali.ui.search
import androidx.recyclerview.widget.GridLayoutManager
import com.fhx.core.base.BaseFragment
import com.fhx.core.utils.ToastUtils
import com.yuanxing.oushangyidali.R
import com.yuanxing.oushangyidali.dialog.AmendDialog
import com.yuanxing.oushangyidali.ui.adapter.SearchAdapter
import kotlinx.android.synthetic.main.fragment_search.*
/**
 * @auther : hhx
 * @date   :  2021/3/16
 * @des    :
 */
class SearchFragment : BaseFragment() {
    private val searchAdapter by lazy { SearchAdapter(mutableListOf()) }
    private var searchlist = mutableListOf<String>()
    override fun getLayoutId(): Int = R.layout.fragment_search
    override fun main() {
        super.main()
        initsearch()
        bt_search.setOnClickListener { v ->
            searchAdapter.setNewInstance(searchlist)
        }
    }

    private fun initsearch() {
        for (i in 1..6) {
            searchlist.add("衬衫" + i)
        }
        recycler_search.layoutManager = GridLayoutManager(context, 1)
        recycler_search.adapter = searchAdapter
        searchAdapter.setOnItemChildClickListener { adapter, view, position ->
            when (view.id) {
                R.id.tv_reduce -> {
                    ToastUtils.show("减少")
                }
                R.id.tv_add -> {
                  showInviteDialog()
                }
            }
        }
    }

    private fun showInviteDialog() {
        val inviteDialog = AmendDialog(object : AmendDialog.CallbackListener {
            override fun callBack(inviteId: String) {
                ToastUtils.show(inviteId)
             }
        })
        inviteDialog.show(childFragmentManager, inviteDialog.tag)
    }
}